#!/bin/sh

CURR_DEV_FILE="current.txt"
SAME_DEV_FILE="same.txt"
IGNORE_DEV_FILE="$1"
CONNECTED_DEV_FILE="$2"

get_uninit_dev()
{
    cat $CURR_DEV_FILE $IGNORE_DEV_FILE | sort | uniq -d > $SAME_DEV_FILE
    cat $CURR_DEV_FILE $SAME_DEV_FILE | sort | uniq -u >> $CONNECTED_DEV_FILE
}

if [ -n "$1" ] && [ -n "$2" ]
then
    echo "sh get params $1 $2"
    rm -f $CURR_DEV_FILE
    rm -f $SAME_DEV_FILE
    rm -rf $2

    ls /dev/ttyUSB* > $CURR_DEV_FILE
    get_uninit_dev
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!usb pass"

    line=$(df | grep -a "/dev/sd")
    #echo $line
    path=${line%% *}
    echo $path > $CURR_DEV_FILE
    get_uninit_dev
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!sd pass"

    rm -f $CURR_DEV_FILE
    path=$(cat /proc/bus/input/devices | grep -a "kbd")
    #echo $path
    while :
    do
        res=${path#* }
        #echo $res
        path=${res#*event}
        #echo $path
        res=${path%% *}
        if echo $res | grep -q '[^0-9]'
        then
            break
        else
            echo /dev/input/event$res >> $CURR_DEV_FILE
            echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!kbd process"
        fi
    done
    get_uninit_dev
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!kbd pass"

    ls /dev/video* > $CURR_DEV_FILE
    get_uninit_dev
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!video pass"

    line=$(ifconfig -a | grep -a "usb")
    #echo $line
    path=${line%% *}
    echo $path > $CURR_DEV_FILE
    get_uninit_dev
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!net pass"
   
    line=$(df | grep -a "/dev/mmcblk2")
    #echo $line
    path=${line%% *}
    echo $path > $CURR_DEV_FILE
    get_uninit_dev
    echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!sdcard pass"
 
    rm -f $CURR_DEV_FILE
    rm -f $SAME_DEV_FILE
else
    echo "sh get null params"
fi
